﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MassiveBattle.Controller.Boss
{
	public class BossController_10004 : BaseBossController
	{
		#region Attack Phase1
		private void Execute_Attack_Phase1()
		{
			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST).GetTake(1, Query.ECount.TAUNT)))
				return;

			SetDamagePoint(SetDamagePoint_Attack_A);

			PlayTake_Attack_Source_Target();
		}
		#endregion

		#region Skill Phase1
		private void Execute_Skill_Phase1()
		{
			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST).GetTake(3, Query.ECount.TAUNT)))
				return;

			SetDamagePoint(SetDamagePoint_Skill_A);

			PlayTake_Skill_Source_Target_Camera();

			AttachCamera_Skill_B();
		}
		#endregion

		#region Skill Phase2
		private IDictionary<object, BaseController> minionMap = new Dictionary<object, BaseController>();

		private void Execute_Skill_Phase2()
		{
			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST)))
				return;

			SetDamagePoint(SetDamagePoint_Skill_A);

			PlayTake_Skill_Source();
		}

		private void event_gameobject_01(object[] paramList)
		{
			var take = Manager.TakePool["MassBattle/sprigg/spriggbomb"];

			foreach (var target in TargetList)
				StartCoroutine(GenerateMinion(paramList[0] as GameObject, take, target));
		}

		private IEnumerator GenerateMinion(GameObject resource, EventlineTake take, BaseController target)
		{
			yield return new WaitForSeconds(Random.Range(0f, 0.6f));

			var main = Instantiate(resource) as GameObject;
			main.transform.position = ModelTransform.position;

			var start = new GameObject();
			start.transform.position = ModelTransform.position + Quaternion.Euler(0f, Random.Range(0f, -180f), 0f) * (Vector3.right * 3f);

			minionMap[start] = target;

			Eventline.Play(take, new[] { main, target.ModelGameObject, start, target.ModelGameObject }, gameObject);

			GameObject.Destroy(start, 5f);
		}

		private void event_gameobject_02(object[] paramList)
		{
			if (paramList[0] == null)
				return;

			var controller = minionMap[paramList[0]];

			controller.Damage(PointDic[controller], true, this);

			minionMap.Remove(paramList[0]);
		}
		#endregion
	}
}
